<template>
  <div>
    <el-form
      :inline="true"
      :model="formData"
      size="small"
      class="demo-form-inline"
    >
      <el-form-item prop="mobile" label="手机号码">
        <el-input
          v-model="formData.mobile"
          clearable
          placeholder="手机号码"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="mobile" label="手机号" width="120">
      </el-table-column>
      <el-table-column prop="nickName" label="昵称" width="120">
      </el-table-column>
      <el-table-column prop="groupName" label="群名" width="200">
      </el-table-column>
      <el-table-column prop="gerFlag" label="是否可发言" width="110">
      </el-table-column>
      <el-table-column fixed="right" label="操作">
        <template slot-scope="scope">
          <el-button
            type="danger"
            size="mini"
            @click="updateGerFlag(scope.row.id, 0)"
            v-if="scope.row.gerFlag === 1"
            >禁言</el-button
          >
          <el-button
            v-else
            type="success"
            size="mini"
            @click="updateGerFlag(scope.row.id, 1)"
            >发言</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <v-pagination :formData="formData" @load="getData"></v-pagination>
  </div>
</template>
<script>
import { queryimGroupUserList, updateGerFlag } from "@/api/imManagement";
import pagination from "@/components/pagination";
export default {
  components: {
    vPagination: pagination,
  },
  data() {
    return {
      loading: true,
      formData: {
        mobile: "",
        pageNo: 1,
        pageSize: 10,
        total: 0,
      },
      tableData: [],
    };
  },
  created() {
    this.getData();
  },
  methods: {
    onSubmit() {
      this.formData.pageNo = 1;
      this.formData.pageSize = 10;
      this.formData.total = 0;
      this.getData();
    },
    getData() {
      console.log(this.formData)
      queryimGroupUserList(this.formData).then((res) => {
        this.loading = false;
        this.tableData = res.data.resultData.groupUserList;
        this.formData.total = res.data.resultData.count;
      });
    },
    updateGerFlag(id, status) {
      this.$msgbox({
        title: "",
        message: "是否确定修改状态",
        showCancelButton: true,
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        beforeClose: (action, instance, done) => {
          if (action === "confirm") {
            instance.confirmButtonLoading = true;
            const formData = {
              id: id,
              status: status,
            };
            updateGerFlag(formData).then((res) => {
              instance.confirmButtonLoading = false;
              if (res.data.errorCode === 200) {
                this.getData();
                done();
                this.$message.success(res.data.errorMessage || "设置成功");
              }
            });
          } else {
            done();
          }
        },
      });
    },
  },
};
</script>